package com.study.flink.datastream.source.noparallel;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

/**
 * 自定义不支持并行度Source产生数据
 * @author stephen
 * @create 2019-01-26 10:59
 * @since 1.0.0
 */
public class NoParallelSource implements SourceFunction<Long> {

    boolean isStop = false;

    /**
     * 产生数据
     * @param sourceContext
     * @throws Exception
     */
    @Override
    public void run(SourceContext sourceContext) throws Exception {
        long i = 0 ;
        while (!isStop){
            sourceContext.collect(i++);
            // 300毫秒产生一条数据
            Thread.sleep(300);
        }
    }

    @Override
    public void cancel() {
        isStop = true;
    }



}
